import java.io.*;
import javax.bluetooth.*;
import javax.microedition.io.*;

public class DateServ {
	public static void main(String args[]) {
		// Since no service record is needed, LocalDevice is not needed.

		// for L2CAP, protocol name btl2cap is used.
		UUID uuid = new UUID("102030405060708090A0B0C0D0E0F011", false);
		String url = "btl2cap://localhost:" + uuid.toString()
				+ ";ReceiveMTU=512;TransmitMTU=512";

		try {
			// 1. create service record
			L2CAPConnectionNotifier n = (L2CAPConnectionNotifier) Connector
					.open(url);

			System.out.println("Waiting to be connected...");

			// 3.ready to accept connection: will block until a client connects
			L2CAPConnection conn = n.acceptAndOpen();

			// send and receive data
			String message = "Hello World";
			int is = conn.getReceiveMTU();
			int os = conn.getTransmitMTU();
			conn.send(message.getBytes());
			byte[] rbuf = new byte[is];
			conn.receive(rbuf);
			System.out.println("Received: " + new String(rbuf));
			conn.close();
		} catch (Exception e) {
			System.out.println("ERROR: connection failed.");
		}
	}
}